package cn.dduan.fool.thread.pool.scheduled;

import cn.dduan.fool.thread.pool.task.MyRunnable;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 通过scheduleWithFixedDelay()延迟执行任务
 *
 * @author dduan
 * @version 1.0
 * @date 2023/3/19
 */
public class MyScheduleWithFixedDelay {
    public static void main(String[] args) {
        // 1.获取一个具备延迟执行任务的线程池对象
        ScheduledExecutorService es = Executors.newScheduledThreadPool(3);
        // 2.创建多个任务对象，提交任务，每个任务延迟2秒执行
        es.scheduleWithFixedDelay(new MyRunnable(1), 1, 2, TimeUnit.SECONDS);
    }
}
